Re: (maybe OT) GTK and IP send?



El miÃ, 11 de 02 de 2004 a las 09:31, Daniel Miralles GarcÃa escribiÃ:
Is any way on GTK or GLib to "send" a packet to an IP without 
confirmation? I mean, something like..

g_ipsend(192,168,2,15,&packet,packet_size)

without having to create any socket?

I'm not sure if you're speaking about to don't create a socket yourself,
or about the machine to comunicate via ethernet without sockets.

If it's the first I'm sure there may be any lib that let you do that,
but if you want to broke in any way the standard you'll need libdnet.

I mean you can send a raw UDP packet, with no confirmation as the
protocol let you do that. If you want to send a TCP packet, you will
need to do the three way handsake, so at leat you must pass and receive
some packets to the remote host, to open a TCP socket. 

And if not in GTK, where? (I've read a little about gNetLibrary but it 
requires to create some sockets).

Could you please tell me if you want a socket-less comunication, or a
lib that build and inject the packets throught a socket with a single
function call ?

With "a packet", what do you mean ? TCP, UDP, IPX ...

If what you want is just create a connection, but don't want to send nor
receive anything, you can use the function below:

#include <resolv.h>
#include <stdio.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string.h> 
#include <stdlib.h>
#include <unistd.h>

#define MAXBUF 1024


void
create_tcp_socket_and_close(char* host, char* port)
{
  struct sockaddr_in addr;
  int sd;

  if( (sd = socket(PF_INET, SOCK_STREAM,0))<0)
    {
      printf("Can't create socket");
      return;
    }

   memset(&addr,0,sizeof(addr));
   addr.sin_family = AF_INET;
   addr.sin_port = htons(atoi(port));

   if(!(inet_aton(host, &addr.sin_addr)))
    {
      printf("ip : '%s' not valid\n",host);
      return;
    }

   /* start conn */
   if( connect(sd,(struct sockaddr *) &addr, sizeof(addr)) != 0)
    {
      printf("Can't connect ... ");
      return;
    }else{
        printf("Connected ... ");
    }

    close(sd);
}

NOTE: it's not tested and from memory.

Sorry if it is offtopic...

I'm sure about that ;)

p.s. if anyone doesn't want to response to everyone, please e-mail me...

I've sent it to the list, but feel free to mail me privately about this
regard as I'm sure It must not be discused here further.



Un saludo :)
-- 
Iago Rubio                http://www.iagorubio.com          
GPGkey pgp.rediris.es id 0x909BD4DD  fingerprint =
D18A B950 5F03 BB9A DD89  AA75 FEDF 1978 909B D4DD
********** iago.rubio(AT)hispalinux.es  **********     
--------------------------------------------------

Attachment: signature.asc
Description: Esta parte del mensaje =?ISO-8859-1?Q?est=E1?= firmada digitalmente



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]