🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: be.comp.programming
Article #13765

Re: HELP WITH SOCKET IN C

#13765
From: Misra
Date: Thu, 31 May 2001 18:16
265 lines
7912 bytes
Hi Luc,
  The program is compiling with a different compiler . But with Borland C++
5.5 it still refuses to compile . It gives the error "Unresolved external
'_main' referenced from c:\borland\bcc55\lib\cox32.obj". With a different
compiler it compiles perfectly . Can you tell me why it does not compile
with BC++ 5.5 . The code is as follows:

#include<winsock.h>
#include<windows.h>
#include<stdio.h>
#include<string.h>


#include <shellapi.h>
#include <stdlib.h>


struct WSAData WSAD;


int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR
lpszCmdLine,int nCmdShow)
   {



   SOCKET sockdesc,new_sd;
   int theirsize;
   struct sockaddr_in my_addr;
   struct sockaddr_in their_addr;
   WSAStartup( MAKEWORD( 1, 1 ),&WSAD);
   memset(&my_addr,0,sizeof(struct sockaddr_in));
   memset(&their_addr,0,sizeof(struct sockaddr_in));


   my_addr.sin_family=AF_INET;
   my_addr.sin_addr.s_addr=htonl(INADDR_ANY);
   my_addr.sin_port=htons(23);

   sockdesc=socket(AF_INET,SOCK_STREAM,0);
   if(sockdesc<0)
    {
   printf("err in socket %d \n",sockdesc);
           }


   if((bind(sockdesc,(struct sockaddr *) &my_addr,sizeof(struct
sockaddr_in)))<0)
   {
     printf("err in bind \n");
   }

   if((listen(sockdesc,2))<0)
   {
     printf("err in listen");
   }
   theirsize=sizeof(struct sockaddr_in);
   new_sd=accept(sockdesc,&their_addr,&theirsize);
   if(new_sd<0)
   {
     printf("err in accept %d \n",new_sd);
   }
   }



"Luc Kumps" <NOkumpsSPAM@pandora.be> wrote in message
news:ilUQ6.20119$X03.1791188@afrodite.telenet-ops.be...
> Could you please show the actual source code that's still giving errors.
> You should insert the code I gave you between your original lines:
>
> > > >    struct sockaddr_in their_addr;
> struct WSAData WSAD;
>
> if (WSAStartup(0x0101,&WSAD)!=0) {
>   printf("WSAStartup failed\n");
>   exit(1);
> }
> > > >    memset(&my_addr,0,sizeof(struct sockaddr_in));
>
> Luc
>
> "Misra" <zxxx999xxxz@yahoo.com> wrote in message
> news:9f0qur$1jpov$1@ID-67106.news.dfncis.de...
> > hi,
> > thanks for the tip. I tried it. but I am still getting errors.First I
put
> > the lines inside main. It gave me a error "this declaration is not
allowed
> > inside . SO I placed it outside main. Still I am getting errors. My
> > winsock.dll version is 4.10.1656
> > ----- Original Message -----
> > From: "Luc Kumps" <NOkumpsSPAM@pandora.be>
> > Newsgroups: be.comp.programming
> > Sent: Tuesday, May 29, 2001 10:55 PM
> > Subject: Re: HELP WITH SOCKET IN C
> >
> >
> > > You forgot to call WSAStartup, which is necessary to initialize the
> > Windows
> > > socket library.
> > > Just add this add the start of your program:
> > >
> > > struct WSAData WSAD;
> > >
> > > if (WSAStartup(0x0101,&WSAD)!=0) {
> > >   printf("WSAStartup failed\n");
> > >   exit(1);
> > > }
> > >
> > >
> > > Luc
> > >
> > >
> > >
> > > "Misra" <zxxx999xxxz@yahoo.com> wrote in message
> > > news:9f0lp7$1j1ff$1@ID-67106.news.dfncis.de...
> > > > Hi,
> > > > Please tell me why this piece of code in C is not working. I am
using
> > the
> > > > free version of Borland c++5.5 compiler available for download. When
I
> > > > execute the .exe file the socket descriptor returns a value of -1 .
I
> am
> > > > using win 95.
> > > >
> > > >
> > > > #include<winsock.h>
> > > > #include<windows.h>
> > > > #include<stdio.h>
> > > > #include<string.h>
> > > >
> > > > int main(void)
> > > >    {
> > > >    SOCKET sockdesc,new_sd;
> > > >    int theirsize;
> > > >    struct sockaddr_in my_addr;
> > > >    struct sockaddr_in their_addr;
> > > >
> > > >    memset(&my_addr,0,sizeof(struct sockaddr_in));
> > > >    // memset(&their_addr,0,sizeof(struct sockaddr_in));
> > > >
> > > >
> > > >    my_addr.sin_family=AF_INET;
> > > >    my_addr.sin_addr.s_addr=htonl(INADDR_ANY);
> > > >    my_addr.sin_port=htons(23);
> > > >
> > > >    sockdesc=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
> > > >
> > > >    printf("err in socket %d \n",sockdesc);
> > > >
> > > >
> > > >
> > > >    if((bind(sockdesc,(struct sockaddr *) &my_addr,sizeof(struct
> > > > sockaddr_in)))<0)
> > > >    {
> > > >      printf("err in bind \n");
> > > >    }
> > > >
> > > >    if((listen(sockdesc,2))<0)
> > > >    {
> > > >      printf("err in listen");
> > > >    }
> > > >    theirsize=sizeof(struct sockaddr_in);
> > > >    new_sd=accept(sockdesc,&their_addr,&theirsize);
> > > >    if(new_sd<0)
> > > >    {
> > > >      printf("err in accept %d \n",new_sd);
> > > >    }
> > > >    }
> > > >
> > > >
> > > >
> > >
> > >
> >
> > "Luc Kumps" <NOkumpsSPAM@pandora.be> wrote in message
> > news:lYQQ6.19798$X03.1687837@afrodite.telenet-ops.be...
> > > You forgot to call WSAStartup, which is necessary to initialize the
> > Windows
> > > socket library.
> > > Just add this add the start of your program:
> > >
> > > struct WSAData WSAD;
> > >
> > > if (WSAStartup(0x0101,&WSAD)!=0) {
> > >   printf("WSAStartup failed\n");
> > >   exit(1);
> > > }
> > >
> > >
> > > Luc
> > >
> > >
> > >
> > > "Misra" <zxxx999xxxz@yahoo.com> wrote in message
> > > news:9f0lp7$1j1ff$1@ID-67106.news.dfncis.de...
> > > > Hi,
> > > > Please tell me why this piece of code in C is not working. I am
using
> > the
> > > > free version of Borland c++5.5 compiler available for download. When
I
> > > > execute the .exe file the socket descriptor returns a value of -1 .
I
> am
> > > > using win 95.
> > > >
> > > >
> > > > #include<winsock.h>
> > > > #include<windows.h>
> > > > #include<stdio.h>
> > > > #include<string.h>
> > > >
> > > > int main(void)
> > > >    {
> > > >    SOCKET sockdesc,new_sd;
> > > >    int theirsize;
> > > >    struct sockaddr_in my_addr;
> > > >    struct sockaddr_in their_addr;
> > > >
> > > >    memset(&my_addr,0,sizeof(struct sockaddr_in));
> > > >    // memset(&their_addr,0,sizeof(struct sockaddr_in));
> > > >
> > > >
> > > >    my_addr.sin_family=AF_INET;
> > > >    my_addr.sin_addr.s_addr=htonl(INADDR_ANY);
> > > >    my_addr.sin_port=htons(23);
> > > >
> > > >    sockdesc=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
> > > >
> > > >    printf("err in socket %d \n",sockdesc);
> > > >
> > > >
> > > >
> > > >    if((bind(sockdesc,(struct sockaddr *) &my_addr,sizeof(struct
> > > > sockaddr_in)))<0)
> > > >    {
> > > >      printf("err in bind \n");
> > > >    }
> > > >
> > > >    if((listen(sockdesc,2))<0)
> > > >    {
> > > >      printf("err in listen");
> > > >    }
> > > >    theirsize=sizeof(struct sockaddr_in);
> > > >    new_sd=accept(sockdesc,&their_addr,&theirsize);
> > > >    if(new_sd<0)
> > > >    {
> > > >      printf("err in accept %d \n",new_sd);
> > > >    }
> > > >    }
> > > >
> > > >
> > > >
> > >
> > >
> >
> >
> >
> >
>
>
Technical Details
Message-ID: <9f62jm$2dru1$2@ID-67106.news.dfncis.de>
Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!fu-berlin.de!uni-berlin.de!203.199.236.38!not-for-mail
References: <9f0lp7$1j1ff$1@ID-67106.news.dfncis.de> <lYQQ6.19798$X03.1687837@afrodite.telenet-ops.be> <9f0qur$1jpov$1@ID-67106.news.dfncis.de> <ilUQ6.20119$X03.1791188@afrodite.telenet-ops.be>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: fcea4,25dfc4a0520414ec
X-Google-Attributes: gidfcea4,public
X-Google-ArrivalTime: 2001-05-31 11:30:18 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!fu-berlin.de!uni-berlin.de!203.199.236.38!not-for-mail
From: "Misra" <zxxx999xxxz@yahoo.com>
Newsgroups: be.comp.programming
Subject: Re: HELP WITH SOCKET IN C
Date: Thu, 31 May 2001 23:46:14 +0530
Lines: 271
Message-ID: <9f62jm$2dru1$2@ID-67106.news.dfncis.de>
References: <9f0lp7$1j1ff$1@ID-67106.news.dfncis.de> <lYQQ6.19798$X03.1687837@afrodite.telenet-ops.be> <9f0qur$1jpov$1@ID-67106.news.dfncis.de> <ilUQ6.20119$X03.1791188@afrodite.telenet-ops.be>
NNTP-Posting-Host: 203.199.236.38
X-Trace: fu-berlin.de 991333816 2551745 203.199.236.38 (16 [67106])
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.50.4133.2400
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400