Возможно вы искали: 'Chessmaster: Grandmast...'

May 15 2025 19:27:52
  • Как сделать 8Gamers.Ru домашней страницей?
  • Игры
    • База данных по играх
    • Игровые новости
    • Игровая индустрия
    • Обзоры на игры
    • Прохождения игр
    • Гайды к играм
    • Превью о играх
    • Игровые тизеры
    • Игровые арты
    • Игровые обои
    • Игровые скриншоты
    • Игровые обложки
    • Игровые трейлеры
    • Игровое видео
    • Вышедшие игры
    • Ближайшие релизы игр
  • Кино и ТВ
    • База данных по кино
    • Статьи о кино
    • Постеры
    • Кадры из кино
    • Кино трейлеры
    • Сегодня в кино
    • Скоро в кино
  • Комиксы и манга
    • Манга по алфавиту
    • База данных по комиксах
    • Читать онлайн комиксы
    • Читать онлайн манга
    • База персонажей
  • Читы и коды
    • Чит-коды для PC игр
    • Чит-коды для консольных игр
    • Трейнеры
    • Коды Game Genie
  • Моддинг
    • Модификации
    • Карты к играм
    • Программы для моддинга
    • Статьи о моддинге
  • Геймдев
    • Всё о создании игр
    • Список движков
    • Утилиты в помощь игроделу
    • Конструкторы игр
    • Игровые движки
    • Библиотеки разработки
    • 3D-модели
    • Спрайты и тайлы
    • Музыка и звуки
    • Текстуры и фоны
  • Рецензии
    • Игры
    • Кино
    • Аниме
    • Комиксы
    • Мангу
    • Саундтреки
  • Саундтреки
    • Лирика
  • Файлы
    • Патчи к играм
    • Русификаторы к играм
    • Сохранения к играм
    • Субтитры к кино
  • Медиа
    • Видео
    • Фото
    • Аудио
    • Фан-арты
    • Косплей
    • Фото с виставок
    • Девушки из игр
    • Рисунки
    • Рисуем онлайн
    • Фотохостинг
  • Юмор
    • Анекдоты
    • Афоризмы
    • Истории
    • Стишки и эпиграммы
    • Тосты
    • Цитаты
  • Флеш
    • Азартные
    • Аркады
    • Бродилки
    • Гонки
    • Для девочек
    • Для мальчиков
    • Драки
    • Квесты
    • Леталки
    • Логические
    • Мультфильмы
    • Открытки
    • Приколы
    • Разное
    • Спорт
    • Стратегии
    • Стрелялки
Статистика

Статей: 87772
Просмотров: 96111483
Игры
Injustice:  Gods Among Us
Injustice: Gods Among Us
...
Dark Souls 2
Dark Souls 2
Dark Souls II - вторая часть самой хардкорной ролевой игры 2011-2012 года, с новым героем, сюжето...
Battlefield 4
Battlefield 4
Battlefield 4 - продолжение венценосного мультиплеер-ориентированного шутера от первого ли...
Кино
Steins;Gate
Steins;Gate
Любители японской анимации уже давно поняли ,что аниме сериалы могут дать порой гораздо больше пи...
Ку! Кин-дза-дза
Ку! Кин-дза-дза
Начинающий диджей Толик и всемирно известный виолончелист Владимир Чижов встречают на шумной моск...
Обзоры на игры
• Обзор Ibara [PCB/PS2] 18357
• Обзор The Walking ... 18801
• Обзор DMC: Devil M... 19879
• Обзор на игру Valk... 15877
• Обзор на игру Stars! 17764
• Обзор на Far Cry 3 17948
• Обзор на Resident ... 16024
• Обзор на Chivalry:... 17508
• Обзор на игру Kerb... 17981
• Обзор игры 007: Fr... 16619
Превью о играх
• Превью к игре Comp... 17960
• Превью о игре Mage... 14464
• Превью Incredible ... 14721
• Превью Firefall 13479
• Превью Dead Space 3 16334
• Превью о игре SimC... 14730
• Превью к игре Fuse 15442
• Превью Red Orche... 15542
• Превью Gothic 3 16343
• Превью Black & W... 17354
Главная » Статьи » Разное » SOCK_RAW (raw socket)

SOCK_RAW (raw socket)

Ключевые слова: raw, socket, (найти похожие документы)

_ RU.LINUX (2:5077/15.22) ___________________________________________ RU.LINUX _
From : Sergey I. Clushin 2:5020/400 14 Apr 99 00:57:06
Subj : SOCK_RAW
________________________________________________________________________________
From: "Sergey I. Clushin" <serg@aviacom.ru>

Andrey Kuzmin wrote:
>
> ...
> >Использовать SOCK_PACKET.
> >
>
> А можно поподробнее, т.к. когда я ставлю SOCK_PACKET вместо SOCK_RAW

SOCK_PACKET

Forum: The Linux Kernel Hackers' Guide
Re: Difference between SOCK_RAW SOCK_PACKET (Chris Leung)
Keywords: SOCK_PACKET
Date: Wed, 10 Jun 1998 18:01:01 GMT
From: Eddie Leung <edleung@uclink4.berkeley.edu>
Body-URL: http://www.senie.com/dan/technology/sock_packet.html

f78

Using the SOCK_PACKET mechanism in Linux
To Gain Complete Control of an Ethernet Interface

Daniel Senie
Amaranth Networks, Inc.

I have put together this web page in response to many queries from
multiple people. Rather than continue
to write individual responses, I have put together this page to explain
what I was trying to do, and how I
got it to work.

First, some background. To simulate software that was intended to run on
a different (and not yet built)
platform, I needed a convenient way to exercise the code against live
networks. I first tried using a
Solaris system, using the DLPI driver. This allowed me to do most things,
but failed when I needed to be
able to set the source Ethernet MAC address. The Solaris DLPI driver
provides no way to override the
hardware on a per-packet basis.

Next, I started looking at mechanisms in Linux. The mechanism that seemed
to fit the best was
SOCK_PACKET, which is used by tcpdump among other things. To Make this
work for me, though, it
was necessary to keep the Linux machine from doing anything on the
interface, other than letting my
programs at it.

How To Do It

This information and these instructions work for RedHat Linux 4.2 with a
2.0.30 kernel. I expect they'll
work fine on a 2.0.32 kernel as well, and with other Linux distributions.
I have heard that a better
mechanism for providing this facility is coming in a newer kernel. If or
when I get more information on
that, I'll see about adding another page on that.

First, the interface needs to be told NOT to run ARP. Promiscuous mode
should be enabled if you need
to hear everything on the wire.:

ifconfig eth1 -ARP PROMISC UP 10.1.1.1

Then tell the Linux stack it's not supposed to see any of the traffic to
or from this port:

ipfwadm -O -a deny -P all -S 0/0 -D 0/0 -W eth1
ipfwadm -I -a deny -P all -S 0/0 -D 0/0 -W eth1

In the program, you need to do several things. First, the socket call:

s = socket(AF_INET, SOCK_PACKET, htons(0x0003));

to get the socket set up.

Next I bind the specific Ethernet NIC I want:

struct sockaddr myaddr;

memset(&myaddr, '', sizeof(myaddr));
myaddr.sa_family = AF_INET;
strcpy(myaddr.sa_data, "eth1"); /* or whatever device */

r = bind(s, &myaddr, sizeof(struct sockaddr));

and check the return code for any errors.

Now, when you want to send or receive, this socket is bound to the proper
device. One word of caution,
though, ALWAYS check the received packets to be sure you got them on the
right device. There's a race
condition between making the socket call and the bind call where you'll
get all packets from ALL
interfaces... not what you want!

So, to send a packet:

struct sockaddr from;
int fromlen;

memset(&from, '', sizeof(from));
from.sa_family = AF_INET;
strcpy(from.sa_data, "eth1"); /* or whatever device */
fromlen = sizeof(from);

r = sendto(s, msg, msglen, 0, &from, fromlen);

and check the return code. Note that msg is the pointer to the packet,
starting with the MAC header. Be
sure you put the proper source MAC address into your packets! Also,
msglen is the length of the packet
including the MAC header, but not including the CRC (which I do not worry
about, but the hardware does
supply).

Receive is pretty similar:

struct sockaddr from;
int fromlen;

fromlen = sizeof(from);

r = recvfrom(s, msg, 2048, 0, &from, &fromlen);
if (r == -1)
{
/* deal with error */
}
if
5fc
(strcmp(from.sa_data, "eth1") != 0)
{
/* not from the interface we wanted, discard */
}

if r == -1, you have an error. If r > 0, then r is the length of the
received packet. The strcmp ensures
the packet came from the right interface.

If you want to receive for MAC addresses other than the one the board has
in it, use promiscuous mode.
To get the mac address from your program, there's an ioctl call
SIOCGIFHWADDR. In the return from
that call is also the hardware type, so you can ensure it's Ethernet.
Another call, SIOCGIFMTU will tell
you the MTU of the interface.

Caveats

Do not use this methodology on your primary Ethernet interface.
Instead, install a second (and if
needed, third) NIC card for use in this way. I've successfully used 5
NIC cards in one machine, 1
under the control of Linux, the rest bypassed to my programs.
Be VERY sure you set up the ipfwadm commands. Failure to do so will
make a huge mess, likely
causing networking problems for other hosts on your lan.



If you found this information helpful and useful, please let me know. If
you require further information or
assistance in this area, this can be arranged. For consultation beyond
simple questions, Amaranth
Networks, Inc. can provide advice, services and information for a fee.

Copyright Э 1998, Amaranth Networks, Inc.
All Rights Reserved
0

Предупреждение относительно primary eth можете смело игнорировать.

> то sendto возвращает -1 и ничего не посылает

И вообще, почему-бы Вам не посетить KHG - Kernel Hacker's Guide.
Раньше он была на http://www.redhat.com:8080/HyperNews/get/khg.html
Там в вопросах и ответах много ценного есть. В том числе и ответ на
Ваш вопрос: Difference between SOCK_RAW SOCK_PACKET.

> ... (галиматья выкинута)
>
> Спасибо.

Кушайте на здоровие. Да, еще можете посмотреть tcpdump. В его
исходниках етсь исходниоки libpcap, а в ней используется
SOCK_PACKET. Еще можете Стивенса почитать, последнюю редакцию;
там про SOCK_PACKET в Линухе тоже есть.


--
Best regards.
Sergey.
Всего хорошего.
Сергей.
--- ifmail v.2.14dev3
* Origin: private person (2:5020/400)

1221 Прочтений •  [SOCK_RAW (raw socket)] [08.05.2012] [Комментариев: 0]
Добавил: Ukraine Vova
Ссылки
HTML: 
[BB Url]: 
Похожие статьи
Название Добавил Добавлено
• SOCK_RAW (raw socket) Ukraine Vova 08.05.2012
• IP&TCP SOCK_RAW (setsockopt) (socke... Ukraine Vova 08.05.2012
Ни одного комментария? Будешь первым :).
Пожалуйста, авторизуйтесь для добавления комментария.

Проект входит в сеть сайтов «8Gamers Network»

Все права сохранены. 8Gamers.NET © 2011 - 2025

Статьи
Рецензия на Pressure
Рецензия на Pressure
Чтобы обратить на себя внимание, начинающие маленькие разработчики, как правило, уходят в жанры, ...
Рецензия на Lost Chronicles of Zerzura
Рецензия на Lost Chron...
Игры, сделанные без любви и старания, похожи на воздушный шар – оболочка есть, а внутри пусто. Lo...
Рецензия на The Bridge
Рецензия на The Bridge
«Верх» и «низ» в The Bridge — понятия относительные. Прогуливаясь под аркой, можно запросто перей...
Рецензия на SimCity
Рецензия на SimCity
Когда месяц назад состоялся релиз SimCity, по Сети прокатилось цунами народного гнева – глупые ош...
Рецензия на Strategy & Tactics: World War 2
Рецензия на Strategy &...
Название Strategy & Tactics: World War II вряд ли кому-то знакомо. Зато одного взгляда на ее скри...
Рецензия на игру Scribblenauts Unlimited
Рецензия на игру Scrib...
По сложившейся традиции в информационной карточке игры мы приводим в пример несколько похожих игр...
Рецензия на игру Walking Dead: Survival Instinct, The
Рецензия на игру Walki...
Зомби и продукция-по-лицензии — которые и сами по себе не лучшие представители игровой биосферы —...
Обратная связь | RSS | Донейт | Статистика | Команда | Техническая поддержка