Thread: Need Help With this Code !!!

  1. #1
    Registered User
    Join Date
    Dec 2010
    Lucknow, India

    Need Help With this Code !!!

    I'm trying to Write A Server and Client Program in C.
    After Suffering much I got this Server Program but When i compile it..
    I got an error of
    "Unresolved External '_bzero' referenced from .......(path of server.obj file)"
    Someone help me out.

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <sys/types.h> 
    void error(const char *msg)
    {    perror(msg);    exit(1);}
    int main(int argc, char *argv[])
    {int sockfd, newsockfd, portno, clien, n;
    char buffer[256];
    struct sockaddr_in serv_addr, cli_addr;
    if (argc < 2)
    {fprintf(stderr,"ERROR, no port provided\n"); exit(1);}
    sockfd = socket(AF_INET, SOCK_STREAM, 0);
    if (sockfd < 0)
    error("ERROR opening socket");
    bzero((char *) &serv_addr, sizeof(serv_addr));
    portno = atoi(argv[1]);
    serv_addr.sin_family = AF_INET;
    serv_addr.sin_addr.s_addr = INADDR_ANY;
    serv_addr.sin_port = htons(portno);
    if (bind(sockfd, (struct sockaddr *) &serv_addr,sizeof(serv_addr)) < 0)
    error("ERROR on binding");
    clien = sizeof(cli_addr);
    newsockfd = accept(sockfd,(struct sockaddr *)&cli_addr,&clien);
    if (newsockfd < 0)
    error("ERROR on accept");
    n = read(newsockfd,buffer,255);
    if (n < 0)
    error("ERROR reading from socket");
    printf("Here is the message: %s\n",buffer);
    n = write(newsockfd,"I got your message",18);
    if (n < 0) 
    error("ERROR writing to socket");
    return 0;}
    Compiler: Borland (advance)
    OS: windows XP

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Try using memset() instead.

    Or even something hacky like
    #define bzero(x,y) memset(x,0,y)
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Dec 2010
    Lucknow, India
    Salem...Thanks A Lot Buddy..
    GOD bless You..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Illegal Instruction at perfectly fine Code
    By m00ni in forum C Programming
    Replies: 24
    Last Post: 02-14-2011, 02:56 AM
  2. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 07:34 AM
  3. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 04:17 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 0
    Last Post: 02-21-2002, 06:05 PM