[gnet-dev] new function please
- From: Bernd Demian <bdemian csc-dd de>
- To: gnet-dev gnetlibrary org
- Subject: [gnet-dev] new function please
- Date: 11 Oct 2002 11:27:40 +0200
Hi,
I use gnet very often, but I miss one feature. We have simple industrial
controller, so I must as client bind the socket adress, like following
function.
GTcpSocket*
gnet_tcp_socket_new_bind_direct (const GInetAddr* addr)
{
int sockfd;
GTcpSocket* s;
struct sockaddr_in* sa_in;
struct sockaddr_in local_adresse;
int rv;
g_return_val_if_fail (addr != NULL, NULL);
/* Create socket */
sockfd = socket (AF_INET, SOCK_STREAM, 0);
if (sockfd < 0)
return NULL;
/* Create GTcpSocket */
s = g_new0 (GTcpSocket, 1);
s->sockfd = sockfd;
s->ref_count = 1;
/* bereite bind vor */
memset((void *)&local_adresse, 0, sizeof(local_adresse));
local_adresse.sin_family = AF_INET;
local_adresse.sin_addr.s_addr = htonl(INADDR_ANY);
local_adresse.sin_port = gnet_inetaddr_get_port(addr);
rv = bind(sockfd, (struct sockaddr *)&local_adresse,
sizeof(local_adresse));
if( rv < 0){
GNET_CLOSE_SOCKET(s->sockfd);
g_free(s);
return NULL;
}
/* Set up address and port for connection */
memcpy(&s->sa, &addr->sa, sizeof(s->sa));
sa_in = (struct sockaddr_in*) &s->sa;
sa_in->sin_family = AF_INET;
/* Connect */
rv = connect(sockfd, &s->sa, sizeof(s->sa));
if (rv != 0)
{
GNET_CLOSE_SOCKET(s->sockfd);
g_free (s);
return NULL;
}
return s;
}
This would be very usefull for me.
Thanks Bernd
--
Bernd Demian <bdemian csc-dd de>
CSC Ploenzke
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]