From owner-freebsd-questions Thu Jan 23 4:33:48 2003 Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 03BCD37B401 for ; Thu, 23 Jan 2003 04:33:46 -0800 (PST) Received: from undead.dnn.ru (dnn.ru [212.158.164.253]) by mx1.FreeBSD.org (Postfix) with ESMTP id CDC1D43F1E for ; Thu, 23 Jan 2003 04:33:41 -0800 (PST) (envelope-from alex@dynaweb.ru) Received: from dynaweb.ru (dynaweb.dnn.ru [212.158.164.112]) by undead.dnn.ru (8.9.3/8.9.3) with ESMTP id PAA31135 for ; Thu, 23 Jan 2003 15:35:48 +0300 (MSK) (envelope-from alex@dynaweb.ru) Message-ID: <3E2FE2F6.7000806@dynaweb.ru> Date: Thu, 23 Jan 2003 15:41:26 +0300 From: Alex Reply-To: alex@dynaweb.ru User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.0.1) Gecko/20020823 Netscape/7.0 X-Accept-Language: en-us, en MIME-Version: 1.0 To: freebsd-questions Subject: problems configuring ipfw via raw sockets Content-Type: text/plain; charset=windows-1251; format=flowed Content-Transfer-Encoding: 7bit Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Hi ppl! I need to use direct access to ipfw rules via raw sockets instead of some scripts using ipfw utility. I looked into ipfw sources and made a simple program to test if I could add a simple rule this way. Just rewrote pieces of original code into my program w/out any serious change. But setsockopt() always return EINVAL and string msg "Invalid argument". And no details. Hence I'm in a fix. Icannot get what's wrong indeed. It's my first experience with configuring ipfw this way and maybe I missed something obvious for a guru :0) Here I place my code (short anough). Any advice would be appritiated. Maybe some links to some docs - I failed to find anything but a very short info in manpages. #include #include #include #include #include #include #include #include #include int test(void) { int sock,res,sz; struct ip_fw rule; sock = socket(AF_INET,SOCK_RAW,IPPROTO_RAW); if (sock==-1) {printf("\n\nsoket() failed with \"%s\"\n\n",strerror(errno)); return -1;}; memset(&rule,0,sizeof(struct ip_fw)); rule.fw_number = 700; rule.fw_flg = IP_FW_F_DENY; rule.fw_src.s_addr = inet_addr("195.48.121.34"); rule.fw_smsk.s_addr = inet_addr("255.255.255.255"); rule.fw_dst.s_addr = inet_addr("127.0.0.0"); rule.fw_dmsk.s_addr = inet_addr("255.0.0.0"); rule.fw_prot = IPPROTO_IP; sz = sizeof(struct ip_fw); res = setsockopt(sock,IPPROTO_IP,IP_FW_ADD,&rule,&sz); if (res==-1) {printf("\n\nsetsockopt() failed with \"%s\"\n\n",strerror(errno)); return -1;}; return 0; }; int main(void) { test(); return 0; }; Alexander Komratov To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message