Thread: u_short header?

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    96

    u_short header?

    I am trying to cast a variable using the "ushort" type but am receiving an error of "u_short undeclared: first use of this function". I looked online and saw that it resides in the types.h header but when I try to include this header I receive another error of this header doesn't exist. Is this the correct header which I am trying to include or is there a way to get this header installed so I can make this conversion. Thanks!


    Code:
    #include <types.h>
    
    .....
    
    sin.sin_port = htons((u_short)port);
    
    
    
    
    $make
    $myTCP.c:7:60: error: types.h: No such file or directory
    $myTCP.c: In function ‘myTCPconnect’:
    $myTCP.c:48: error: ‘u_short’ undeclared (first use in this function)

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    My check of sys/types.h online didn't reveal either a "ushort" or a "u_short". (Notice that it would be sys/types.h, not types.h, and that would only work if you actually have it, as it's not a standard header.) I suppose you can check your own types.h, if you have one, and see if there is a "ushort" or a "u_short" defined.

  3. #3
    Registered User
    Join Date
    Nov 2007
    Posts
    96
    I was looking at the header online and I believe that it just assigns "unsigned short" to u_short. After replace the (u_short) with the (unsigned short) everything appears to be working fine. Thank you for your help though.

  4. #4
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by NuNn View Post
    I was looking at the header online and I believe that it just assigns "unsigned short" to u_short. After replace the (u_short) with the (unsigned short) everything appears to be working fine. Thank you for your help though.
    What else would you expect it to be?
    If you want your code to be portable, you should make your own typedefs rather than relying on headers that may not be in all compilers.
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  5. #5
    Registered User bboozzoo's Avatar
    Join Date
    Jan 2009
    Posts
    14
    1. #include <stdint.h>
    2. sys/types.h - as name suggests is system specific (normally this might come with the kernel as it is on Linux, glibc uses particular version of kernel headers which provide sys/types.h), might be u_short on one system, ushort on other system, and perhaps unsigned_short on yet another one, only stdint.h provides uniform typedefs
    3. in stdint you have uint16_t... analogically for other types

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 03:25 PM
  2. Obtaining source & destination IP,details of ICMP Header & each of field of it ???
    By cromologic in forum Networking/Device Communication
    Replies: 1
    Last Post: 04-29-2006, 02:49 PM
  3. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM