Implicit declaration

This is a discussion on Implicit declaration within the C Programming forums, part of the General Programming Boards category; I'm trying to learn up on socket programming, so I took a sample program and tried compiling it, I'm getting ...

  1. #1
    Cogito Ergo Sum
    Join Date
    Mar 2007
    Location
    Sydney, Australia
    Posts
    463

    Implicit declaration

    I'm trying to learn up on socket programming, so I took a sample program and tried compiling it, I'm getting implict declarations for bzero and close.

    Code:
    #include <stdio.h>
    #include <sys/types.h>
    #include <sys/socket.h>
    #include <netinet/in.h>
    #include <arpa/inet.h>
    #include <errno.h>
    #include <stdlib.h>
    
    #define MY_PORT_ID     6089              
    #define SERVER_PORT_ID     6090              
    #define SERV_HOST_ADDR "128.119.40.186"  
    
    main()
    {
       int sockid, retcode;
       struct sockaddr_in my_addr, server_addr;
       char msg[12];
       
       printf("Client: creating socket\n");
          if ( (sockid = socket(AF_INET, SOCK_DGRAM, 0)) < 0) 
          { printf("Client: socket failed: %d\n",errno); exit(0); }
    
    
       printf("Client: binding my local socket\n");
       bzero((char *) &my_addr, sizeof(my_addr));
       my_addr.sin_family = AF_INET;
       my_addr.sin_addr.s_addr = htonl(INADDR_ANY);
       my_addr.sin_port = htons(MY_PORT_ID);
       if ( (bind(sockid, (struct sockaddr *) &my_addr, 
                  sizeof(my_addr)) < 0) )
          { printf("Client: bind fail: %d\n",errno); exit(0); }   
    
       printf("Client: creating addr structure for server\n");
       bzero((char *) &server_addr, sizeof(server_addr));
       server_addr.sin_family = AF_INET;
       server_addr.sin_addr.s_addr = inet_addr(SERV_HOST_ADDR);
       server_addr.sin_port = htons(SERVER_PORT_ID);
    
       printf("Client: initializing message and sending\n");
       sprintf(msg,  "Hello world");
       retcode = sendto(sockid,msg,12,0,(struct sockaddr *) &server_addr,
     		    sizeof(server_addr));
       if (retcode <= -1)
         {printf("client: sendto failed: %d\n",errno); exit(0); }   
    
       /* close socket */
       close(sockid);
     }

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    bzero(x, sizeof(x)) is a short version of memset(x, 0, sizeof(x)), so you can probably get rid of that.

    Not sure what you should do about close - is this a windows or Linux system?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Cogito Ergo Sum
    Join Date
    Mar 2007
    Location
    Sydney, Australia
    Posts
    463
    Windows system

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Perhaps closesocket - I'm only googling and guessing based on googles results, but I don't think I'm far off.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Cogito Ergo Sum
    Join Date
    Mar 2007
    Location
    Sydney, Australia
    Posts
    463
    I'll try

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Quantum Random Bit Generator
    By shawnt in forum C++ Programming
    Replies: 62
    Last Post: 06-18-2008, 10:17 AM
  2. failure to import external C libraries in C++ project
    By nocturna_gr in forum C++ Programming
    Replies: 3
    Last Post: 12-02-2007, 02:49 PM
  3. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 04:45 PM
  4. Errors with including winsock 2 lib
    By gamingdl'er in forum C++ Programming
    Replies: 3
    Last Post: 12-05-2005, 07:13 PM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21