Return-Path: william@bourbon.usc.edu Delivery-Date: Fri Aug 29 19:34:27 2008 X-Spam-Checker-Version: SpamAssassin 3.2.3 (2007-08-08) on merlot.usc.edu X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=AWL,BAYES_40, LOCALPART_IN_SUBJECT autolearn=no version=3.2.3 Received: from bourbon.usc.edu (bourbon.usc.edu [128.125.9.75]) by merlot.usc.edu (8.14.1/8.14.1) with ESMTP id m7U2YRJT028814 for ; Fri, 29 Aug 2008 19:34:27 -0700 Received: from bourbon.usc.edu (localhost.localdomain [127.0.0.1]) by bourbon.usc.edu (8.14.2/8.14.1) with ESMTP id m7U2fUqR029618 for ; Fri, 29 Aug 2008 19:41:30 -0700 Message-Id: <200808300241.m7U2fUqR029618@bourbon.usc.edu> To: cs551@merlot.usc.edu Subject: Re: cs551 Date: Fri, 29 Aug 2008 19:41:30 -0700 From: Bill Cheng Someone wrote: > I have the following problem. When i set buf[0]=(char)0xfe and send it on > the other side, i can view this hex value using printf("%x",buf[0]) but how > can i compare this to 0xfe in order to ensure that it is an ADDR request (or > some other depending on buf[1]). I tried converting buf[0] to hex value > using itoa() but it is not in ANSI C library. What can be the workaround ? If you want to see if buf[0] is 0xfe, you can just do: if (buf[0] == 0xfe) { ... } Since MessageType is a 16-bit quantity, you can use uint16_t. So, you can define an uint16_t variable: uint16_t messge_type; Then copy 2 bytes from buf to this variable using memcpy(). Then you should call ntohs() to make your code work on both Solaris and Linux, then you can do: if (message_type == 0xfe10) { ... } -- Bill Cheng // bill.cheng@usc.edu