Need Help With this Code !!!

This is a discussion on Need Help With this Code !!! within the Networking/Device Communication forums, part of the General Programming Boards category; Hi. I'm trying to Write A Server and Client Program in C. After Suffering much I got this Server Program ...

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

    Need Help With this Code !!!

    Hi.
    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.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <sys/types.h> 
    #include<winsock.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");
    listen(sockfd,5);
    clien = sizeof(cli_addr);
    newsockfd = accept(sockfd,(struct sockaddr *)&cli_addr,&clien);
    if (newsockfd < 0)
    error("ERROR on accept");
    bzero(buffer,256);
    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");
    close(newsockfd);
    close(sockfd);
    return 0;}
    Compiler: Borland (advance)
    OS: windows XP

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,337
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Dec 2010
    Location
    Lucknow, India
    Posts
    72
    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, 01: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, 03: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, 05:05 PM

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