[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c++

per packet QoS (DSCP

aapocketz

12/8/2008 9:01:00 PM

My application calls for sending different UDP packets with different
QoS priority, using DSCP. To do this I wanted to modify the ToS byte
in the IP header (bits 8-15 of the IPv4 header) on a per packet
basis.

It appears that this is possible using "ancillary data" and sendmsg/
recvmsg() API and the cmsg routines (http://manpages.u...
manpages/intrepid/man3/cmsg.html) to modify the header fields.

I cannot get this to work. Can anyone provide an example that does?
I am using ubuntu 8.10 and I have tried several things. Here is a
current little test client. Looking at wireshark I do not see any
changes to the TOS field (stays zero no matter what). I even tried
changing things like TTL field without any luck either. Any ideas?

#include <arpa/inet.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <stdlib.h>
#include <string>
#include <string.h>

#define BUFLEN 512
#define NPACK 10
#define PORT 9930

void diep(const char *s) {
perror(s);
exit(1);

}

#define SRV_IP "127.0.0.1"
/* diep(), #includes and #defines like in the server */

int main(void) {
sockaddr_in si_other = {0};
msghdr msg = {0};
int s, i;
char buf[BUFLEN];

if ((s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1)
diep("socket");

si_other.sin_family = AF_INET;
si_other.sin_port = htons(PORT);
if (inet_aton(SRV_IP, &si_other.sin_addr) == 0) {
fprintf(stderr, "inet_aton() failed\n");
exit(1);
}

for (i = 0; i < NPACK; i++) {
printf("Sending packet %d\n", i);
sprintf(buf, "This is packet %d\n", i);
//if (sendto(s, buf, BUFLEN, 0, (sockaddr *)&si_other,
slen) == -1)
// diep("sendto()");

// sets the address to send to
msg.msg_name = &si_other;
msg.msg_namelen = sizeof(si_other);

iovec iov[1];
msg.msg_iov = iov ;
msg.msg_iovlen = 1;
int test = 0xEFBEADDE;

iov[0].iov_base = &test;
iov[0].iov_len = sizeof test;

// sets the control ancillary data
cmsghdr * cmsg;
//int tos = 0xBEBAFECA; // set to low delay
int tos = 6; // set to low delay

char buf[CMSG_SPACE(sizeof(tos))];
msg.msg_control = buf;
msg.msg_controllen = sizeof(buf);

cmsg = CMSG_FIRSTHDR(&msg); // set to first header
if(cmsg == NULL)
{
fprintf(stderr, "CMSG_FIRSTHDR FAILED");
exit(1);
}
// first header is the TOS header
cmsg->cmsg_level = IPPROTO_IP;
cmsg->cmsg_type = IP_TOS;
cmsg->cmsg_len = CMSG_LEN(sizeof(tos));
*((int *) CMSG_DATA(cmsg)) = tos;
//void * data = CMSG_DATA(cmsg); // set the data
//memcpy(data, (void*) &tos, sizeof(tos));
msg.msg_controllen = cmsg->cmsg_len;

if (sendmsg(s, &msg, 0) < 0)
diep("sendmsg()");
}

close(s);
return 0;
11 Answers

Jack Klein

12/9/2008 3:34:00 AM

0

On Mon, 8 Dec 2008 13:01:17 -0800 (PST), aapocketz
<aapocketz@gmail.com> wrote in comp.lang.c++:

> My application calls for sending different UDP packets with different
> QoS priority, using DSCP. To do this I wanted to modify the ToS byte
> in the IP header (bits 8-15 of the IPv4 header) on a per packet
> basis.


[snip platform specific code with non-standard headers]

news:comp.unix.programmer

But read their FAQ first.

--
Jack Klein
Home: http://JK-Tech...
FAQs for
comp.lang.c http://...
comp.lang.c++ http://www.parashift.com/c++...
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-...

William Black

7/2/2014 3:12:00 PM

0

On Wed, 2 Jul 2014 10:37:34 -0400, "Allen W. McDonnell"
<Tanada@peakoil.com> wrote:

>
>"SolomonW" <SolomonW@citi.com> wrote in message
>news:lftwxeqn0246$.1e89w9cc2otco.dlg@40tude.net...
>> On Sat, 28 Jun 2014 10:25:49 -0400, Allen W. McDonnell wrote:
>>
>>> At the demand of the American government the UK reluctantly agrees to
>>> proceed with the Invasion of Normandy in early 1943.
>>
>> In winter ??
>>
>>
>
>YMMV but I consider May 18 to be Spring, not Winter.

When did the coastal areas thaw in 1943?

And will the Germans use Alpine troops to hold on the mountains?

The Horny Goat

7/2/2014 3:48:00 PM

0

On Wed, 2 Jul 2014 10:37:34 -0400, "Allen W. McDonnell"
<Tanada@peakoil.com> wrote:

>"SolomonW" <SolomonW@citi.com> wrote in message
>news:lftwxeqn0246$.1e89w9cc2otco.dlg@40tude.net...
>> On Sat, 28 Jun 2014 10:25:49 -0400, Allen W. McDonnell wrote:
>>
>>> At the demand of the American government the UK reluctantly agrees to
>>> proceed with the Invasion of Normandy in early 1943.
>>
>> In winter ??
>
>YMMV but I consider May 18 to be Spring, not Winter.

The German invasion of Norway started April 9, 1940 - and I am fairly
sure most would consider Norway to have a colder climate than Normandy
in mid-spring. The main 1940 campaign started May 10th. Overlord was
originally planned for May 1944 and delayed primarily due to tide
conditions and availability of landing craft (primarily getting them
from the Pacific and Italy to southern England)

The main differences a May 1943 invasion would have are that in May
1943 the U-boat war was not yet won, nor did the Allies have the air
superiority typical of 1944.

Rich Rostrom

7/2/2014 6:14:00 PM

0

The Horny Goat <lcraver@home.ca> wrote:

> The main differences a May 1943 invasion would have are that in May
> 1943 the U-boat war was not yet won

Arguably, the Battle of the Atlantic _was_
won in May 1943 - _in_ that month. The
Allies sank 41 U-boats while losing only
58 freighters - a loss ration of only 1.41.

That ratio had been 18.85 across the previous
44 months of the war, and 26.86 for May 1940
through November 1942.

It was only 1.59 for the rest of 1943.

But of course, the BoA had not been won in
late 1942/early 1943, when the decision to
invade in 1943 would have to be made.
--
The real Velvet Revolution - and the would-be hijacker.

http://originalvelvetrevo...

Allen W. McDonnell

7/2/2014 6:35:00 PM

0


"Rich Rostrom" <rrostrom.21stcentury@rcn.com> wrote in message
news:rrostrom.21stcentury-CEEBDD.13140902072014@mx05.eternal-september.org...
> The Horny Goat <lcraver@home.ca> wrote:
>
>> The main differences a May 1943 invasion would have are that in May
>> 1943 the U-boat war was not yet won
>
> Arguably, the Battle of the Atlantic _was_
> won in May 1943 - _in_ that month. The
> Allies sank 41 U-boats while losing only
> 58 freighters - a loss ration of only 1.41.
>
> That ratio had been 18.85 across the previous
> 44 months of the war, and 26.86 for May 1940
> through November 1942.
>
> It was only 1.59 for the rest of 1943.
>
> But of course, the BoA had not been won in
> late 1942/early 1943, when the decision to
> invade in 1943 would have to be made.


True enough, but the same mass production techniques that won the BoA in May
1943 with CVE ships was also producing freighters at much much faster rate
than Germany could sink them. Even during the 'Happy Time' in 1942 the USA
was building freighters faster than they could be sunk, along with an ever
growing number of long range patrol aircraft, CVE escort carriers,
Destroyers, Frigates and Corvettes for ASW and on and on. When the American
forces went into North Africa in late 1942 most of them considered it the
dress rehearsal for the invasion of France the following year, and almost a
third of those assault ships traveled directly from the east coast of North
America. Correctly or not the American military saw the invasion of France
as being practical for 1943 despite the German U-Boot threat.
--
Allen W. McDonnell

http://www.amazon.com/Lost-Submariner-Log-Allen-McDonnell-ebook/dp/B...
http://www.amazon.com/Grantville-Gazette-IV-Ring-Fire-ebook/dp/B...

SolomonW

7/3/2014 2:38:00 PM

0

On Wed, 2 Jul 2014 14:35:09 -0400, Allen W. McDonnell wrote:

> Correctly or not the American military saw the invasion of France
> as being practical for 1943 despite the German U-Boot threat.

It should be pointed out here that the British military which was more
experienced felt it was not.



---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www...

Allen W. McDonnell

7/3/2014 2:59:00 PM

0


"SolomonW" <SolomonW@citi.com> wrote in message
news:givntt0fir1n.1k5v73j2b6d6d.dlg@40tude.net...
> On Wed, 2 Jul 2014 14:35:09 -0400, Allen W. McDonnell wrote:
>
>> Correctly or not the American military saw the invasion of France
>> as being practical for 1943 despite the German U-Boot threat.
>
> It should be pointed out here that the British military which was more
> experienced felt it was not.
>
>
>

Correct, OTL the President, FDR, was swayed by the beliefs of the UK
military industrial complex to delay the invasion of France for a year. In
this ATL he died in July 1942 of a stroke. President Wallace was swayed the
other way by the combination of the USA Military opinion coupled with Joseph
Stalin all but demanding the invasion take place ASAP.


--
Allen W. McDonnell

http://www.amazon.com/Lost-Submariner-Log-Allen-McDonnell-ebook/dp/B...
http://www.amazon.com/Grantville-Gazette-IV-Ring-Fire-ebook/dp/B...

Larry Headlund

7/3/2014 3:08:00 PM

0

On Thursday, July 3, 2014 10:37:54 AM UTC-4, SolomonW wrote:
> On Wed, 2 Jul 2014 14:35:09 -0400, Allen W. McDonnell wrote:
> > Correctly or not the American military saw the invasion of France
>
> > as being practical for 1943 despite the German U-Boot threat.
>
>
>
> It should be pointed out here that the British military which was more
>
> experienced felt it was not.

How experienced was any military in amphibious invasions against hostile forces in 1943? Recent experience only.

British: Norway 1940 was not against hostile forces.
British and US: Torch in 1942, Sicily was in mid-1943
US: Pacific island assaults.
Germany: Crete was an airborne assault, Norway
Japan: Hong Kong, Singapore, Indonesia.

I would say a 1943 continental amphibious invasion would be a risky venture but no one really had the experience to know.

William Black

7/3/2014 4:19:00 PM

0

On Thu, 3 Jul 2014 08:07:47 -0700 (PDT), Larry Headlund
<lmh@world.std.com> wrote:

>On Thursday, July 3, 2014 10:37:54 AM UTC-4, SolomonW wrote:
>> On Wed, 2 Jul 2014 14:35:09 -0400, Allen W. McDonnell wrote:
>> > Correctly or not the American military saw the invasion of France
>>
>> > as being practical for 1943 despite the German U-Boot threat.
>>
>>
>>
>> It should be pointed out here that the British military which was more
>>
>> experienced felt it was not.
>
>How experienced was any military in amphibious invasions against hostile forces in 1943? Recent experience only.
>
>British: Norway 1940 was not against hostile forces.
>British and US: Torch in 1942, Sicily was in mid-1943
>US: Pacific island assaults.
>Germany: Crete was an airborne assault, Norway
>Japan: Hong Kong, Singapore, Indonesia.
>
>I would say a 1943 continental amphibious invasion would be a risky venture but no one really had the experience to know.

The major stopper was the Dieppe Raid in August 1942 where all the
armour bogged down on the pebble beach due to jammed tracks, fire
support was inadequate and radio security was dreadful and the Germans
were alerted to something happening.

To counter all this a series of specialised armoured vehicles were
developed and fire support systems were built. Things like the
'Hobart's Funnies', the devastating Landing Ship (Rocket) and the
training of destroyer crews for close in fire support.

Also a huge deception plan (Operation BODYGUARD) was started.

All these developments were underway but incomplete in before the
middle of 1943.

PLUTO was operational but MULLBERRY wasn't and the OVERLORD planners
knew they couldn't capture a port in the first six weeks.

If you invade Europe in 1943 you do it without armour, without a port
and without massive fire support...

Larry Headlund

7/3/2014 7:07:00 PM

0

On Thursday, July 3, 2014 12:18:43 PM UTC-4, Bill wrote:
> On Thu, 3 Jul 2014 08:07:47 -0700 (PDT), Larry Headlund
> >On Thursday, July 3, 2014 10:37:54 AM UTC-4, SolomonW wrote:
>
> >> On Wed, 2 Jul 2014 14:35:09 -0400, Allen W. McDonnell wrote:
>
> >> > Correctly or not the American military saw the invasion of France
>
> >>
>
> >> > as being practical for 1943 despite the German U-Boot threat.
> >> It should be pointed out here that the British military which was more
> >> experienced felt it was not.
> >How experienced was any military in amphibious invasions against hostile forces in 1943? Recent experience only.
> >British: Norway 1940 was not against hostile forces.
>
> >British and US: Torch in 1942, Sicily was in mid-1943
>
> >US: Pacific island assaults.
>
> >Germany: Crete was an airborne assault, Norway
>
> >Japan: Hong Kong, Singapore, Indonesia.
> >I would say a 1943 continental amphibious invasion would be a risky venture but no one really had the experience to know.
>
>
>
> The major stopper was the Dieppe Raid in August 1942 where all the
>
> armour bogged down on the pebble beach due to jammed tracks, fire
>
> support was inadequate and radio security was dreadful and the Germans
>
> were alerted to something happening.
>
>
>
> To counter all this a series of specialised armoured vehicles were
>
> developed and fire support systems were built. Things like the
>
> 'Hobart's Funnies', the devastating Landing Ship (Rocket) and the
>
> training of destroyer crews for close in fire support.
>
>
>
> Also a huge deception plan (Operation BODYGUARD) was started.
>
>
>
> All these developments were underway but incomplete in before the
>
> middle of 1943.
>
>
>
> PLUTO was operational but MULLBERRY wasn't and the OVERLORD planners
>
> knew they couldn't capture a port in the first six weeks.
>
>
>
> If you invade Europe in 1943 you do it without armour, without a port
>
> and without massive fire support...

Don't know how I forgot to mention Dieppe. Of course, there was some minor US Army and mostly Canadian troops involved so the experience should of been shared all around.