linux-gcc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Paula Berger <pberger@inf.ufrgs.br>
To: linux-gcc@vger.kernel.org
Subject: IOCTL problem!!!
Date: Tue, 28 Oct 2003 16:46:37 +0000	[thread overview]
Message-ID: <200310281642.35530.pberger@inf.ufrgs.br> (raw)


	Hi everybody.. I'm new here, so let's see if you guys can help me :-)

	I'm trying to use the ioctl function with the SIOCADDRT flag and I'm having 
some problems! What i want to do is simply add the default gateway to my 
routing table. I'm using the struct rtentry (don't know if I'm using it 
correctly though) then I create a datagram socket and the I use the ioctl 
function... Does anyone know what's wrong? 
	I'm sending my source as an example... if someone could please help me, I 
REALLY nedd to do this!!!
	Thanks,

--
Paula Berger
E-mail: pberger@inf.ufrgs.br
--

EXAMPLE:

int main() {
	uint32_t IpAddr;
	uint32_t Dst;
	uint32_t GenMask;
	struct sockaddr_in Route;
	struct rtentry Entry;
	int SockFd, res = 0;

	memset ((char *)&Entry, 0, sizeof (struct rtentry));

	Entry.rt_gateway.sa_family = AF_INET;
	Entry.rt_genmask.sa_family = AF_INET;
	Entry.rt_dst.sa_family = AF_INET;
	Entry.rt_flags = RTF_UP | RTF_GATEWAY;

	if(inet_aton("0.0.0.0", (struct in_addr *)&GenMask) == 0)
		printf("\nroute genmasc error\n");

	if(inet_aton("143.54.83.0", (struct in_addr *)&Dst) == 0)
		printf("\nroute dst error\n");

	if(inet_aton("143.54.83.1", (struct in_addr *)&IpAddr) == 0)
		printf("\nroute ip error\n");

	Route.sin_addr.s_addr = htonl(IpAddr);
	memcpy(&Entry.rt_gateway, &Route, sizeof(struct sockaddr));

	Route.sin_addr.s_addr = htonl(Dst);
	memcpy(&Entry.rt_dst, &Route, sizeof(struct sockaddr));

	Route.sin_addr.s_addr = htonl(GenMask);
	memcpy(&Entry.rt_genmask, &Route, sizeof(struct sockaddr));

	if ((SockFd = socket(PF_INET, SOCK_DGRAM, 0)) < 0) {
		perror("socket");
		return -1;
    	}

	res = ioctl(SockFd, SIOCADDRT, &Entry);

	if (res < 0) {
            perror("\nerror: ");
	    close(SockFd);
	    return -1;
        }

	close(SockFd);

	return 0;
}

                 reply	other threads:[~2003-10-28 16:46 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200310281642.35530.pberger@inf.ufrgs.br \
    --to=pberger@inf.ufrgs.br \
    --cc=linux-gcc@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).