This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: errors


The orignal code contains some errors ... but there's no compilation error.
Why compiler version are you using?
What compiler options?

	Yves

// Original code
        if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
            perror("socket");
            exit(1);
        }

        their_addr.sin_family = AF_INET;     // host byte order
        their_addr.sin_port = htons(MYPORT); // short, network byte order
        their_addr.sin_addr = *((struct in_addr *)he->h_addr);
        memset(&(their_addr.sin_zero), '\0', 8); // zero the rest of the
struct

// Portable, "correct" and safe code
        if ((sockfd = socket(PF_INET, SOCK_DGRAM, 0)) == -1) {
            perror("socket");
            exit(1);
        }

        memset(&their_addr, 0, sizeof(their_addr)); // zero the struct
        their_addr.sin_family = AF_INET;     // host byte order
        their_addr.sin_port = htons(MYPORT); // short, network byte order
	  memcpy(&their_addr.sin_addr,he->h_addr_list[0],sizeof(struct in_addr));

> -----Message d'origine-----
> De : gcc-help-owner@gcc.gnu.org [mailto:gcc-help-owner@gcc.gnu.org]De la
> part de Rahul it
> Envoyé : dimanche 26 mai 2002 15:50
> À : gcc-help@gcc.gnu.org
> Objet : errors
>
>
> am running a code and it gives me the following error
>
> chhabra@noix{networking} 1028 : gcc -c talker.c
> talker.c: In function `main':
> talker.c:39: dereferencing pointer to incomplete type
>
>
> I know there is some problem with the line. I have tried but I am
> unable to find it out.
>
> their_addr.sin_addr=*((struct in_addr *)he->h_addr);
>
> As I am new in this, this is just an example taken from
> Beejs Guide to Network Programming
>
> Section 5.3 Datagram Sockets
> talker.c
>
> The source code is on the link
>
>
> http://www.ecst.csuchico.edu/~beej/guide/net/html/clientserver.htm
l#datagram

Someone Please help.
Thanks
Shalendra



_________________________________________________________
Click below to visit monsterindia.com and review jobs in India or
Abroad
http://monsterindia.rediff.com/jobs


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]