This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
socket call failed under g++ option.
- To: "'egcs-bugs'" <egcs-bugs at egcs dot cygnus dot com>
- Subject: socket call failed under g++ option.
- From: Thang Vu <Thang dot Vu at digital dot com>
- Date: Wed, 24 Mar 1999 15:37:04 -0500
- Cc: Thang Vu <Thang dot Vu at digital dot com>
I have egcs 1.1.2 installed on my linux 2.2.3 kernel machine. The
socket call failed if I build my code using g++ instead of gcc. Here is
the code
//////////////////////////////////////////// test.cc
///////////////////////////////
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <netinet/in.h> /* sockaddr_in structure */
#include <arpa/inet.h>
#include <unistd.h>
#include <stdio.h>
int main()
{
// to get the protocol
struct protoent *proto;
int my_socket;
// now get the protocol --> This is OK for both g++ and gcc
if (!(proto = getprotobyname("icmp")))
{
printf("No ICMP protocol supported\n");
return -1;
}
// create an ICMP socket ->> This call failed if using
g++
my_socket = socket(AF_INET, SOCK_RAW,proto->p_proto);
if (my_socket < 0){
printf("Invalid Socket\n");
}
return 0;
}
--Thang