Re: to bernie: more on mixedlib.e and other stuff

new topic     » goto parent     » topic index » view thread      » older message » newer message

>I understand all of your code above just fine. There is one thing that i
need
>clarrified though. When i look at online C socket tutorials for berkley
sockets
>i see the author always typecast a sockaddr_in structure to sockaddr and
>then pass it to accept( ) instead of just using a sockaddr struct in the
first
>place
>
>What would be the use of this?


 cense:

    I assume that this is what you are talking about.

     struct sockaddr_in client;
     int fd;
     client_len = sizeof(client);
     fd = accept(sock, (struct sockaddr *) &client, &client_len);


    The reason for this is that the real accept function prototype
    is:
     accept(int s, const void* addr, int addrlen)

    You will notice that the SECOND parameter is a VOID POINTER.
    A void pointer in "C" is a general type of pointer ( or holds a
    general address ) that can be assigned any type of pointer
    ( or address ). The void pointer can NOT be derefernced UNTIL
    it is FIRST CAST to ANOTHER type. SO because we are using the
    REFERENCE OPERATOR & ( or address operator ) we have to do a CAST
    to tell "C" to treat the VOID POINTER as a GENERIC SOCKADDR
    STRUCTURE POINTER. That means we can point to ANY SOCKADDR
    STRUCTURE TYPE. The sockaddr_in is only one of these types of
    structures.

    Hope that clears this up for you.

    Bernie



could benitialized
    to different

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu