Skip to content

Commit

Permalink
Merge pull request #684 from bytedance/feat-ipv6
Browse files Browse the repository at this point in the history
feat ipv6 address
  • Loading branch information
yoloyyh authored Sep 23, 2024
2 parents b7456fb + 7dfcc98 commit 7360c20
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
25 changes: 24 additions & 1 deletion rasp/librasp/src/nodejs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ fn parse_port_from_address(address: &str) -> Option<u16> {
pub fn get_process_listening_port(pid: i32) -> u16 {
let tcp_path = format!("/proc/{}/net/tcp", pid);

// frist get ipv4 listen port
if let Ok(content) = std::fs::read_to_string(tcp_path) {

for line in content.lines().skip(1) {
Expand All @@ -55,7 +56,29 @@ pub fn get_process_listening_port(pid: i32) -> u16 {
if status == "0A" {
if let Some(port) = parse_port_from_address(local_address) {
if (NODEJS_INSPECT_PORT_MIN..= NODEJS_INSPECT_PORT_MAX).contains(&port) {
info!("Found listen port {} for pid {}", port, pid);
info!("Found IPv4 listen port {} for pid {}", port, pid);
return port;
}
}
}
}
}
}

// get ipv6 listen port
let tcp6_path = format!("/proc/{}/net/tcp6", pid);
if let Ok(content) = std::fs::read_to_string(tcp6_path) {

for line in content.lines().skip(1) {
let parts: Vec<&str> = line.split_whitespace().collect();
if parts.len() >= 3 {
let local_address = parts[1];
let status = parts[3];

if status == "0A" {
if let Some(port) = parse_port_from_address(local_address) {
if (16680..= NODEJS_INSPECT_PORT_MAX).contains(&port) {
info!("Found IPv6 listen port {} for pid {}", port, pid);
return port;
}
}
Expand Down
6 changes: 3 additions & 3 deletions rasp/librasp/src/parse_elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ pub fn find_by_symbol(elf: &Elf, file: &File) -> Result<String> {
Ok(version)
} else {
let msg = format!("file {:?} Failed to find symbol: runtime.buildVersion", file);
warn!("{}", msg);
// warn!("{}", msg);
Err(anyhow!(msg))
}
}
Expand Down Expand Up @@ -223,12 +223,12 @@ pub fn find_by_section(elf: &Elf, buffer:&Vec<u8>, file: &File) -> Result<String
return Ok(version);
} else {
let msg = format!("file {:?} Failed to find magic header: {:?}", file, magic_header);
warn!("{}", msg);
// warn!("{}", msg);
return Err(anyhow!(msg));
}
} else {
let msg = format!("file {:?} Failed to find section:.go.buildinfo", file);
warn!("{}", msg);
// warn!("{}", msg);
Err(anyhow!(msg))
}
}

0 comments on commit 7360c20

Please sign in to comment.