Solved

Problem sending/receiving radius accounting UDP packet using winsock

Posted on 2010-08-24
5
948 Views
Last Modified: 2013-11-29
I'm trying to send a radius auth start/stop message using winsock in a C++ program.
I have all the values inc. shared secret, and I believe I am forming a valid radius packet inc. MD5 hash but I can't be 100% sure.
I don't control the radius server I'm trying to hit...

NTRadPing 1.5 works fine, but on the same machine, my app doesn't (i.e. the packet never gets there or is ignored). My packet length is the same length as the one that ntradping is sending, with what I believe are all the same parameters.

Assuming my radius packet is correctly set up, how do I make my winsock code work properly to read a response?
The "recv()" call hangs - perhaps because the radius server is ignoring or not receiving the message.

I'm having trouble reading the response. Here is what I'm trying to do with winsock (leaving out error handling and such):


WSADATA     wsadata;
SOCKET      sendSocket      = NULL;
sockaddr_in      recvAddr;
DWORD      dwPort      = 1813;
char *      szHostIP      = "1.2.3.4"; // real IP hidden

WSAStartup(MAKEWORD(1, 1), &wsadata);
sendSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
recvAddr.sin_family = AF_INET;
recvAddr.sin_port = htons((u_short)dwPort);
recvAddr.sin_addr.s_addr = inet_addr(szHostIP);
connect(sendSocket, (SOCKADDR *)&recvAddr, sizeof(recvAddr));
send(sendSocket, (const char *)rgbBuf, cbLen, 0);

recv(sendSocket, achBufRecv, min(20, sizeof(achBufRecv)), 0);

closesocket(sendSocket);
WSACleanup();
0
Comment
Question by:povjetset
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 27

Accepted Solution

by:
BigRat earned 0 total points
ID: 33519763
>>The "recv()" call hangs - perhaps because the radius server is ignoring or not receiving the message.

Correct. The recv() will wait until DATA arrives.

>>I'm having trouble reading the response

Yes, even if UPD works corretly this can still occur. The correct procedure is to use the select() call with a time-out value, or use it in a polling fashion, and ONLY call recv() when select() says that there is something to be read.

Lastly I don't connect using UPD but I use sendto(). This link gives an example of BOTH systems, TCP and UDP. See trhe senderprog.c bit.

http://www.tenouk.com/Module40c.html

Note that you then need to use recvFrom() to pick up the reply.

HTH
0
 

Author Comment

by:povjetset
ID: 33525986
that helps with theblocking issue, thanks, however:

1. (stupid question): the response from the radius server is going to come back to my sendSocket, right? (i.e. I don't need to create a second receive socket, which wouldn't make sense!)

2. I still have the issue of not knowing if the packet is even reaching the radius server... the send still returns sucess even if I use a bogus ip address and port...
0
 
LVL 27

Expert Comment

by:BigRat
ID: 33529711
1. Correct. You just use recvFrom() using the same socket.

2. That I don't quite understand. Are you using the sendTo() interface?
0
 

Author Comment

by:povjetset
ID: 33538114
send or sendTo, neither is working.
I ran wireshark and compared my packet to one sent successfully by ntradping and I noticed this important difference:

my winsock code's packet: wireshark says it's just a UDP protocol packet with [Protocols in frame: eth:ip:udp:data]
ntradping packet: wireshark says it's a radius protocol packet with [Protocols in frame: eth:ip:udp:radius]
(this is in the main frame of the packet)

So what/where can I set something that will change it from a data to a radius packet?
0
 

Author Comment

by:povjetset
ID: 33546977
final mystery solved: the length inside the data portion of my radius packet was little endian instead of big endian. once I fixed that, then wireshark recognized it as a radius packet!
0

Featured Post

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Short answer to this question: there is no effective WiFi manager in iOS devices as seen in Windows WiFi or Macbook OSx WiFi management, but this article will try and provide some amicable solutions to better suite your needs.
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question